package ab.mes.controller;

import ab.mes.entity.BinStock;
import ab.mes.entity.FinishedProductBinStock;
import ab.mes.service.impl.BinStockServiceImpl;
import ab.mes.service.impl.FinishedProductBinStockServiceImpl;
import ab.mes.tools.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/binStock")
public class BinStockController {
    @Autowired
    private BinStockServiceImpl binStockService;

    //查询物料库位信息
    @PostMapping("/getBinStock")
    public Result getBinStock(){
        Result result=new Result();
        try {
            result = binStockService.getBinStock();
        }catch (Exception e){
            result.setErrorMessage("查询物料库位失败！");
            e.printStackTrace();
        }
        return result;
    }

    //查询库位编号物料库位信息
    @PostMapping("/getBinStockById")
    public Result getBinStockById(String Id){
        Result result=new Result();
        try {
            result = binStockService.getBinStockById(Id);
        }catch (Exception e){
            result.setErrorMessage("查询库位失败！");
            e.printStackTrace();
        }
        return result;
    }


    //编辑库位
    @PostMapping("/editBinStock")
    public Result editBinStock(@RequestBody BinStock binStock){
        Result result=new Result();
        try {
            binStockService.editBinStock(binStock);
        }catch (Exception e){
            result.setErrorMessage("编辑失败！");
            e.printStackTrace();
        }
        return result;
    }

    //新增库位
    @PostMapping("/insertBinStock")
    public Result insertBinStock(@RequestBody BinStock binStock){
        Result result=new Result();
        try {
            binStockService.insertBinStock(binStock);
        }catch (Exception e){
            result.setErrorMessage("新增失败！");
            e.printStackTrace();
        }
        return result;
    }
}
